package com.hulk.ratel.manage.commoncache;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hulk.ratel.common.constant.enums.YesOrNo;
import com.hulk.ratel.persistence.entity.TDictCode;
import com.hulk.ratel.persistence.repository.TDictCodeRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;


/**
 * Created by cmt on 2018/08/03.
 * 字典codeCache
 */
@Slf4j
@Component
public class DictCodeCache {

    @Autowired
    private TDictCodeRepository dictCodeRepository;

    //@Cacheable(value = "dictCodeCache", key = "#dictId+ 'DictCodeCache_findDictCodes'")
    //@Cached(name="DictCodeCache.findDictCodes", key = "#dictId + 'DictCodeCache_findDictCodes'", cacheType = CacheType.BOTH ,localLimit = 4096, localExpire =600 ,expire = 600)
    @Cached(name="DictCodeCache.findDictCodes", key = "#dictId + 'DictCodeCache_findDictCodes'", cacheType = CacheType.LOCAL ,localLimit = 8182, localExpire =600 )
    public java.util.List<TDictCode> findDictCodes(String workId, @Nonnull String dictId) {
        TDictCode dcParam = new TDictCode();
        dcParam.setDictId(dictId);
        dcParam.setCodeFlag(YesOrNo.YES.getValue());
        Wrapper<TDictCode> queryDictCode = new EntityWrapper<>(dcParam);
        return dictCodeRepository.selectList(queryDictCode);
    }
}
